package util;

import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import exceptions.ExceptionBackup;

public class Backup {

	private String nomeBkp = ".sql";
	private String database = "araujo_seguros_local";
	private String usuario = "root";
	private String senha = "AraujoCaneta";

	// ----------------------------------------------------------------------------------
	public boolean executaBackup(String diretorio) throws ParseException,
			SQLException, IOException {
		try {
			String dump = "cmd.exe /c C:/wamp/bin/mysql/mysql5.5.24/bin/mysqldump --user=" + usuario
					+ " --password=" + senha + " " + database + " > "
					+ diretorio + nomeBkp;
			
			Runtime bkp = Runtime.getRuntime();
			bkp.exec(dump);
			return true;
		} catch (IOException ex) {
			new ExceptionBackup();
		}
		return false;
	}

	// ----------------------------------------------------------------------------------
	public boolean restauraBackup(String diretorio) throws ParseException,
			SQLException, IOException {

		try {

			String restauraBkp = "cmd.exe /c C:/wamp/bin/mysql/mysql5.5.24/bin/mysql --user=" + usuario
					+ " --password=" + senha + " " + database + " < "
					+ diretorio;
			
			Runtime.getRuntime().exec(restauraBkp);
			return true;
		} catch (IOException ex) {
			
			new ExceptionBackup();
		}
		return false;
	}
	// ----------------------------------------------------------------------------------
}
